package dmsxl.tanxin;

import java.util.Arrays;

/**
 * Author: Zhang Dongwei
 * Date: 2023/8/1 11:49
 */
public class tx17_452 {

    public static void main(String[] args) {
//        int[][] points = {{10, 16}, {2, 8}, {1, 6}, {7, 12}};
        int[][] points = {{1, 2}, {3, 4}, {5, 6}, {7, 8}};
        System.out.println(findMinArrowShots(points));
    }

    public static int findMinArrowShots(int[][] points) {
        Arrays.sort(points, (a, b) -> Integer.compare(a[0], b[0]));
//        Arrays.sort(points, (a, b) -> {  // 有问题
//            return a[0] - b[0];
//        });
        int arrow = 1;
        for (int i = 1; i < points.length; i++){
            if (points[i][0] > points[i - 1][1]){
                arrow ++;
            }else {
                points[i][1] = Math.min(points[i - 1][1], points[i][1]);
            }
        }
        return arrow;
    }
}
